package com.galaxy.commom.base.message;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 响应结果封装类
 * @author caijinbang
 * @date 2018/10/27 16:56
 */

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value = "请求结果响应体")
public class ResponseResult<T> implements Serializable {


  @ApiModelProperty(value = "响应状态回执码")
  private Integer status;

  @ApiModelProperty(value = "数据体")
  private T data;

  @ApiModelProperty(value = "响应回执消息")
  private String msg;

  @ApiModelProperty(value = "响应时间戳")
  private final long timestamps = System.currentTimeMillis();

  public synchronized static <T> ResponseResult<T> e(ResponseCode statusEnum) {
    return e(statusEnum,null);
  }

  public synchronized static <T> ResponseResult<T> e(ResponseCode statusEnum, T data) {
    ResponseResult<T> res = new ResponseResult<>();
    res.setStatus(statusEnum.code);
    res.setMsg(statusEnum.msg);
    res.setData(data);
    return res;
  }
}
